package com.up.management.controller;

import com.up.common.annotation.Log;
import com.up.common.core.controller.BaseController;
import com.up.common.core.domain.AjaxResult;
import com.up.common.core.page.TableDataInfo;
import com.up.common.enums.BusinessType;
import com.up.common.utils.poi.ExcelUtil;
import com.up.management.domain.entity.EventRegion;
import com.up.management.service.IEventRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 地区管理Controller
 * 
 * @author cloud
 * @date 2025-10-09
 */
@RestController
@RequestMapping("/management/EventRegion")
public class EventRegionController extends BaseController
{
    @Autowired
    private IEventRegionService eventRegionService;

    /**
     * 查询地区管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:EventRegion:list')")
    @GetMapping("/list")
    public TableDataInfo list(EventRegion eventRegion)
    {
        startPage();
        List<EventRegion> list = eventRegionService.selectEventRegionList(eventRegion);
        return getDataTable(list);
    }

    /**
     * 导出地区管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:EventRegion:export')")
    @Log(title = "地区管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EventRegion eventRegion)
    {
        List<EventRegion> list = eventRegionService.selectEventRegionList(eventRegion);
        ExcelUtil<EventRegion> util = new ExcelUtil<EventRegion>(EventRegion.class);
        util.exportExcel(response, list, "地区管理数据");
    }

    /**
     * 获取地区管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:EventRegion:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eventRegionService.selectEventRegionById(id));
    }

    /**
     * 新增地区管理
     */
    @PreAuthorize("@ss.hasPermi('management:EventRegion:add')")
    @Log(title = "地区管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EventRegion eventRegion)
    {
        return toAjax(eventRegionService.insertEventRegion(eventRegion));
    }

    /**
     * 修改地区管理
     */
    @PreAuthorize("@ss.hasPermi('management:EventRegion:edit')")
    @Log(title = "地区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EventRegion eventRegion)
    {
        return toAjax(eventRegionService.updateEventRegion(eventRegion));
    }

    /**
     * 删除地区管理
     */
    @PreAuthorize("@ss.hasPermi('management:EventRegion:remove')")
    @Log(title = "地区管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eventRegionService.deleteEventRegionByIds(ids));
    }
}
